package com.bym.controller;

import com.bym.ShoppingCart;
import com.bym.SimulationOrder;
import com.bym.SimulationResponse;
import com.bym.bean.RequestCoupon;
import com.bym.bean.SearchCoupon;
import com.bym.beans.CouponInfo;
import com.bym.entity.Coupon;
import com.bym.service.CouponCustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/coupon-customer")
public class CouponCustomerController {

    @Autowired
    private CouponCustomerService customerService;

    @PostMapping("/requestCoupon")
    public Coupon requestCount(@Valid @RequestBody RequestCoupon request) {
        return customerService.requestCoupon(request);
    }

    // ResponseEntity - 指定返回状态码 - 可以作为一个课后思考题
    @PostMapping("/placeOrder")
    public ShoppingCart placeOrder(@Valid @RequestBody ShoppingCart order) {
        return customerService.placeOrder(order);
    }

    // 用户模拟计算每个优惠券的优惠价格
    @PostMapping("/simulateOrder")
    public SimulationResponse simulateOrder(@Valid @RequestBody SimulationOrder order) {
        return customerService.simulationOrderPrice(order);
    }

    // 用户删除优惠券
    @DeleteMapping("/deleteCoupon")
    public void deleteCoupon(@RequestParam("userId") Long userId, @RequestParam("couponId") Long couponId) {
        customerService.deleteCoupon(userId, couponId);
    }

    // 实现的时候最好封装一个search object类
    @PostMapping("/findCoupon")
    public List<CouponInfo> findCoupon(@Valid @RequestBody SearchCoupon request) {
        return customerService.findCoupon(request);
    }
}
